#ifndef GAMEROOM_H
#define GAMEROOM_H

#include <QWidget>
#include <QSound>
#include <deque>


//枚举蛇的移动方向
enum class SnakeDirect{
    UP=0,
    DOWN,
    LEFT,
    RIGHT
};

namespace Ui {
class GameRoom;
}

class GameRoom : public QWidget
{
    Q_OBJECT

public:
    explicit GameRoom(QWidget *parent = nullptr);
    ~GameRoom();
    void paintEvent(QPaintEvent *event);


    //蛇的移动方向
    void MoveUp();//向上移动
    void MoveDown();//向下移动
    void MoveLeft();//向左移动
    void MoveRight();//向右移动

    //13.检查游戏是否结束
    bool checkFail();

    //15.创建食物
    void CreateFood();

    //22.设置不同的游戏模式
    void setTimeout(int timeout){moveTimeout = timeout;}

    //添加分数到文件中
    void AddScoreToFile();

private:
    Ui::GameRoom *ui;
    GameRoom* gameRoom;
private:
    const int SnakeNodeWidth = 20; //蛇身宽度
    const int SnakeNodeHeight = 20;//蛇身长度
    const int SnakeDefaultTimeout = 200;//蛇的移动速度

    QList<QRectF>snakeList;
    QRectF foodRect;

    SnakeDirect moveDirect = SnakeDirect::UP;
    QTimer *timer;//定时器，设置游戏开始和暂停
    //std::deque<QRectF>snakeDeque;
    bool isGameStart = false;

    QSound *sound;

    //22.设置不同的游戏模式
    int moveTimeout = SnakeDefaultTimeout;
};

#endif // GAMEROOM_H
